package Examples;

import java.util.Properties;



import jsdai.lang.*;
import jsdai.SContext_schema.*;
import jsdai.SGraph_schema.*;
import jsdai.SMfha_graph_schema.*;


public class Example1  {
	
	public static void main(String[] args) throws SdaiException{
		
		//create properties
		Properties prop= new Properties();
		//set working directories
		prop.setProperty("repositories", "/home/ubuntu/workspace_indigo/ProjetLongJSDAI/src/Examples");
		//Set properties to SDaiSession
		SdaiSession.setSessionProperties(prop);
		//open session
		SdaiSession session = SdaiSession.openSession();
		//start read/write transaction
		SdaiTransaction transaction = session.startTransactionReadWriteAccess();
		//import STEP file into a new repository
		SdaiRepository repository = session.importClearTextEncoding("spfRepo8", "/home/ubuntu/Bureau/ProjetLong/ProjetN7/Exemple1/instance_express_MFHA_Example1.stp", null);
		//open repository 
		if (!repository.isActive())
			repository.openRepository();
		//commit data in transaction
		transaction.commit();
		//get SDAIMOdels in the repositpry
		ASdaiModel models =repository.getModels();
		//iterate throw all repository models
		SdaiIterator modelsIt=models.createIterator();
		while(modelsIt.next()){
			//get current Sdai model
			SdaiModel model =models.getCurrentMember(modelsIt);
			//Start read only acces on Sdai model
			if (model.getMode()==SdaiModel.NO_ACCESS)
				model.startReadOnlyAccess();
			System.out.println("Model found : "+model.getName()+"\r\n");
			String shemaname=model.getUnderlyingSchemaString();
			System.out.println("shemafound : "+shemaname+"\r\n");
			//find all instances of entity type MFHA_activator
			EMfha_structure st=(EMfha_structure)model.createEntityInstance(EMfha_structure.class);
			AMfha_structure activators=(AMfha_structure) model.getInstances(EMfha_structure.class);
			//iterate throw found activators
			SdaiIterator activatorIterator = activators.createIterator();
			while(activatorIterator.next()){
				//display activator informations 
				EMfha_structure activator = activators.getCurrentMember(activatorIterator);
				System.out.println ("activator id = "+ activator.getPersistentLabel());
			}
			if (model.getMode()==SdaiModel.READ_ONLY)
				model.endReadOnlyAccess();
		}
		repository.closeRepository();
		transaction.endTransactionAccessCommit();
		session.closeSession();
		System.out.println("\r\n Finish");
	}
}
